package com.sport.facilities.booking.system.httptask;

import android.content.Context;

import com.sport.facilities.booking.system.htmlchecker.MakeBookingPageChecker;
import com.sport.facilities.booking.system.model.MakeBookFormModel;

public class MakeBookingPageTask extends BasicTask {

	public MakeBookingPageTask(Context ctx, OnTaskCompleted completeAction) {
		super(ctx);
		this.listener = completeAction;
	}

	public void fnLoadBookingPage() {
		try {
			super.onPreExecute();
			super.execute(PATH_BOOK_PAGE);
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		MakeBookingPageChecker mbpc = new MakeBookingPageChecker();
		MakeBookFormModel bfm = null;
		try {
			bfm = mbpc.fnGetBookingModelFromHtml(result);
			if (this.listener != null) {
				this.listener.onTaskCompleted(bfm);
			}
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
		
	}

	public void setCompletedAction(OnTaskCompleted completeAction) {
		this.listener = completeAction;
	}

}
